<template>
  <div class="news_content">
    <h3>{{ content.title }}</h3>
    <p>
      <span>发表时间: {{ date }}</span>
    </p>
    <hr />
    <div class="body">{{ content.body }}</div>
    <comment :id="id"></comment>
  </div>
</template>

<script>
import { Toast } from "mint-ui";
import moment from "moment";
import Comment from "./Comment.vue";
export default {
  name: "NewsContent",
  data() {
    return {
      id: this.$route.params.id,
      content: {},
      date: "",
    };
  },
  components: {
    Comment,
  },
  mounted() {
    this.date = moment().format("YYYY-MM-DD HH:mm:ss");
    this.getNewsById();
  },
  methods: {
    getNewsById() {
      this.axios.get(`api/posts/${this.id}`).then(
        (res) => {
          this.content = res.data;
        },
        (err) => {
          Toast(err.message);
        }
      );
    },
  },
};
</script>

<style lang="less" scoped>
.news_content {
  padding: 0 4px;
  h3 {
    color: red;
    font-size: 14px;
    text-align: center;
  }
}
</style>